//
//  LXCarPicTableViewCell.m
//  ZuLinProject
//
//  Created by bancheng on 2021/12/30.
//  Copyright © 2021 LX_App. All rights reserved.
//

#import "LXCarPicTableViewCell.h"
#import "LXPhotoHelper.h"

@interface LXCarPicTableViewCell()
@property(nonatomic)NSString *frontUrl;

@end

@implementation LXCarPicTableViewCell
// 正面上传图片
- (IBAction)clickFrontAction:(UIButton *)sender {
    
    [[LXPhotoHelper shareHelper] showImageViewSelcteWithResultBlock:^(NSDictionary *dic) {
        NSString *imageUrl = dic[@"url"];
        self.frontUrl  = imageUrl;
        imageUrl = [NSString stringWithFormat:@"%@%@",HTTP_URL,imageUrl];
        [self getYingYeZhiZhaoURl:imageUrl];
        
    }];
    
}


#pragma mark---识别图片、新增车辆、获取类型
- (void)getYingYeZhiZhaoURl:(NSString *)url{
    
   NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:url forKey:@"url"];
    [params setObject:@"4" forKey:@"cmd"];
   
    
    
    [MSNetworkManager postRevertUrl:OCR_URL params:params success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        
        if (isSuccess) {
            [self.frontImageView sd_setImageWithURL:[NSURL URLWithString:[NSString urlEncoding:url]]];
            self.frontMaskView.hidden = NO;
            self.frontImageView.hidden = NO;
            
             NSString *dataString = resonseObj;
             NSDictionary *infoDic = [BaseViewController parseJSONStringToNSDictionary:dataString];
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:infoDic];
            [dic setValue:self.frontUrl forKey:@"frontUrl"];
            if (self.frontValue) {
                self.frontValue(dic);
            }
        }
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:YES];

  
}

// 背面上传图片
- (IBAction)clickBackAction:(UIButton *)sender {
    
    [[LXPhotoHelper shareHelper] showImageViewSelcteWithResultBlock:^(NSDictionary *dic) {
        NSString *imageUrl = dic[@"url"];
        imageUrl = [NSString stringWithFormat:@"%@%@",HTTP_URL,imageUrl];
        [self.backImageView sd_setImageWithURL:[NSURL URLWithString:[NSString urlEncoding:imageUrl]] placeholderImage:Image(@"行驶证反面")];
        self.backImageView.hidden = NO;
        self.backMaskView.hidden = NO;
        
        if (self.otherValue) {
            self.otherValue(@{@"backUrl":dic[@"url"]});
        }
        
        
    }];
}
//45°上传
- (IBAction)clickBevelAction:(UIButton *)sender {
    
    [[LXPhotoHelper shareHelper] showImageViewSelcteWithResultBlock:^(NSDictionary *dic) {
        NSString *imageUrl = dic[@"url"];
        imageUrl = [NSString stringWithFormat:@"%@%@",HTTP_URL,imageUrl];
        [self.bevelImageView sd_setImageWithURL:[NSURL URLWithString:[NSString urlEncoding:imageUrl]] placeholderImage:Image(@"车辆45º照片")];
        self.bevelImageView.hidden = NO;
        self.bevelMaskView.hidden = NO;
        if (self.otherValue) {
            self.otherValue(@{@"bevelUrl":dic[@"url"]});
        }
    }];
    
}

// 正面放大
- (IBAction)clickFrontEnlargeAction:(UIButton *)sender {
    
    UIWindow *window = [BaseViewController getCurrentWindow];
    ShowBigImageWithFrameView *ImageShow = [[ShowBigImageWithFrameView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:self.frontImageView.image];
    [window addSubview:ImageShow];

}
// 背面放大
- (IBAction)clickBackEnlargeAction:(UIButton *)sender {
    UIWindow *window = [BaseViewController getCurrentWindow];
    ShowBigImageWithFrameView *ImageShow = [[ShowBigImageWithFrameView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:self.backImageView.image];
    [window addSubview:ImageShow];
}

//45°放大
- (IBAction)clickBevelEnlargeAction:(UIButton *)sender {
    UIWindow *window = [BaseViewController getCurrentWindow];
    ShowBigImageWithFrameView *ImageShow = [[ShowBigImageWithFrameView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:self.bevelImageView.image];
    [window addSubview:ImageShow];
}



@end
